var FG;
if (!FG)
    FG = {};

FG.Dealer = function(opts) {
    var this_ = this;
    this.buyUrl = '/buy/';

    this.buy = function(uri) {
        var url = this_.buyUrl + uri;
        $.ajax(url, {
            dataType: 'json',
            success: function(data) {
                if (!!data) {
                    if (data.result === 'succeeded') {
                        DX.success("成功购买: " + uri);
                        DX.shout('bought', uri)
                    } else if (data.result === 'no_need') {
                        DX.log("无需购买: " + uri);
                        DX.shout('bought', uri)
                    }
                }
            },
            error: function() {
                DX.error("未能成功购买: " + uri + ", 请重试.");
            }
        })
    };

    this.connectSignals()
};

FG.Dealer.prototype.connectSignals = function() {
    var this_ = this;
    DX.on('buy!', function(uri) {
        this_.buy(uri);
    })
};
